package com.demo2do.fms.entity.appraisal;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;

/**
 * 绩效考核单项结果
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "FMS_APPRAISAL_RESULT_ITEM")
@PersistentFormat
public class AppraisalResultItem {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 所属考核 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Appraisal appraisal;
    
    /** 来自单项测试模板 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private AppraisalTemplateItem parent;
    
    /** 所属测试结果 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private AppraisalResult result;
    
    /** 单项测试名称 */
    private String name;
    
    /** 评分上限 */
    private BigDecimal score;
    
    /** 真实评分 */
    private BigDecimal realScore;
    
    /** 创建人 */
    private Long creator;

    /** 创建时间 */
    private Date createTime;

    /** 最后修改人 */
    private Long lastOperator;
    
    /** 最近修改时间 */
    private Date lastModifyTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public AppraisalResultItem() {
    }
    
    /**
     * 
     * @param template
     * @param appraisal
     * @param appraisalResult
     */
    public AppraisalResultItem(AppraisalTemplateItem template, Appraisal appraisal, AppraisalResult appraisalResult, Long operator) {
        this.appraisal = appraisal;
        this.parent = template;
        this.result = appraisalResult;
        this.name = template.getName();
        this.score = template.getScore();
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        this.disabled = false;
    }
    
   /**
    * 
    * @param lastOperator
    * @param realScore
    * @return
    */
    public AppraisalResultItem rate(BigDecimal realScore, Long lastOperator) {
        this.realScore = realScore;
    	this.lastOperator = lastOperator;
    	this.lastModifyTime = new Date();
    	return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public AppraisalResultItem delete(Long operator) {
        this.disabled = true;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the appraisal
     */
    public Appraisal getAppraisal() {
        return appraisal;
    }

    /**
     * @return the parent
     */
    public AppraisalTemplateItem getParent() {
        return parent;
    }

    /**
     * @return the result
     */
    public AppraisalResult getResult() {
        return result;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the score
     */
    public BigDecimal getScore() {
        return score;
    }

    /**
     * @return the realScore
     */
    public BigDecimal getRealScore() {
        return realScore;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param appraisal
     *            the appraisal to set
     */
    public void setAppraisal(Appraisal appraisal) {
        this.appraisal = appraisal;
    }

    /**
     * @param parent
     *            the parent to set
     */
    public void setParent(AppraisalTemplateItem parent) {
        this.parent = parent;
    }

    /**
     * @param result
     *            the result to set
     */
    public void setResult(AppraisalResult result) {
        this.result = result;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param score
     *            the score to set
     */
    public void setScore(BigDecimal score) {
        this.score = score;
    }

    /**
     * @param realScore
     *            the realScore to set
     */
    public void setRealScore(BigDecimal realScore) {
        this.realScore = realScore;
    }

    /**
     * @param creator
     *            the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param createTime
     *            the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastOperator
     *            the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param lastModifyTime
     *            the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled
     *            the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
